// CanvasDoc.cpp: implementation of the CCanvasDoc class.
//
//////////////////////////////////////////////////////////////////////

#include "CanvasDoc.h"
#include "InputDlg.h"
#include "ErrorLogDlg.h"
#include <assert.h>

#define MSG_TITLE "Logo Message"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CCanvasDoc::CCanvasDoc()
{
    m_hCanvas = m_hErrWnd = NULL;
}

CCanvasDoc::~CCanvasDoc()
{
}

void CCanvasDoc::SetCanvasWnd (HWND hCanvas)
{
    assert (hCanvas);
    m_hCanvas = hCanvas;
}

void CCanvasDoc::SetErrInfoWnd (HWND hErrWnd)
{
    assert (hErrWnd);
    m_hErrWnd = hErrWnd;
}

char* CCanvasDoc::inputwindow (char* str)
{
    static char szTxt[INPUT_SIZE];
    CInputDlg dlg;

    dlg.SetPromptText(str);
    szTxt[0] = '\0';
    int ret = dlg.DoModal();
    if (ret == IDCANCEL) {
        return szTxt;
    }
    strncpy(szTxt, dlg.m_szInput, INPUT_SIZE);
    return szTxt;
}

void CCanvasDoc::message (char* str)
{
    ::MessageBox (m_hCanvas, str, MSG_TITLE, MB_OK);
}

void CCanvasDoc::debug_info (char* str)
{
/*    assert (m_hDbgWnd);
    AppendText (m_hDbgWnd, str);*/
#ifdef DEBUG
   OutputDebugString (str);
#endif
}

void CCanvasDoc::error_info (char* str)
{
    assert (m_hErrWnd);
    SendMessage(m_hErrWnd, SHOW_DLG, 0, 0);
    SendMessage(m_hErrWnd, ADD_ERROR, (WPARAM)str, 0);
}


void CCanvasDoc::AppendText (HWND hWnd, char* str)
{
    ::SendMessage (hWnd, EM_SETSEL, (WPARAM)-1, (LPARAM)-1);
    ::SendMessage (hWnd, EM_REPLACESEL, FALSE, (LPARAM) str);
}
